/**
 * 
 */

package com.chengyu.eyc.base;

import java.io.Serializable;

import com.chengyu.eyc.enums.HttpStatusEnum;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * @author kevin
 *
 */
@Data
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = 1401582569826114801L;

    public static <T> ResponseResult<T> failed() {
        return restResult(null, HttpStatusEnum.ERROR_500.code(), HttpStatusEnum.ERROR_500.desc());
    }

    public static <T> ResponseResult<T> failed(int code, String msg) {
        return restResult(null, code, msg);
    }

    public static <T> ResponseResult<T> failed(String msg) {
        return restResult(null, HttpStatusEnum.ERROR_500.code(), msg);
    }

    public static <T> ResponseResult<T> failed(T data) {
        return restResult(data, HttpStatusEnum.ERROR_500.code(), HttpStatusEnum.ERROR_500.desc());
    }

    public static <T> ResponseResult<T> failed(T data, String msg) {
        return restResult(data, HttpStatusEnum.ERROR_500.code(), msg);
    }

    public static <T> ResponseResult<T> ok() {
        return restResult(null, HttpStatusEnum.OK_200.code(), HttpStatusEnum.OK_200.desc());
    }

    public static <T> ResponseResult<T> ok(T data) {
        return restResult(data, HttpStatusEnum.OK_200.code(), HttpStatusEnum.OK_200.desc());
    }

    public static <T> ResponseResult<T> ok(T data, String msg) {
        return restResult(data, HttpStatusEnum.OK_200.code(), msg);
    }

    private static <T> ResponseResult<T> restResult(T data, int code, String msg) {
        ResponseResult<T> apiResult = new ResponseResult<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMessage(msg);
        return apiResult;
    }

    @Getter
    @Setter
    int code = 200;

    @Getter
    @Setter
    String message;

    @Getter
    @Setter
    T data;

}
